package com.wanmait.schedule.controller;

import com.wanmait.schedule.entity.NoticeLevel;
import com.wanmait.schedule.service.NoticeLevelService;
import com.wanmait.schedule.util.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 通知等级表 前端控制器
 * </p>
 *
 * @author wanmait
 * @since 2022-12-05
 */
@RestController
@RequestMapping("/manage/noticeLevel")
@RequiresPermissions("manage:notice")
public class NoticeLevelController {
    @Resource
    private NoticeLevelService noticeLevelService;

    //添加
    @PostMapping("save")
    public AjaxResult noticeLevelSave(@RequestBody NoticeLevel noticeLevel){
        boolean save = noticeLevelService.save(noticeLevel);
        if(save){
            return AjaxResult.success("成功");
        }
        return AjaxResult.error(10001,"失败");
    }

    //列表
    @GetMapping("list")
    public AjaxResult noticeLevelList(){
        List<NoticeLevel> noticeLevelList = noticeLevelService.findAll();
        return AjaxResult.success("成功",noticeLevelList);
    }

    //修改
    @PostMapping("update")
    public AjaxResult noticeLevelUpdate(@RequestBody NoticeLevel noticeLevel){

        boolean flag = noticeLevelService.updateById(noticeLevel);
        if(flag){
            return AjaxResult.success("成功");
        }
        return AjaxResult.error(10001,"失败");
    }

    //删除
    @GetMapping("delete")
    public AjaxResult noticeLevelDelete(Integer id){
        boolean flag = noticeLevelService.removeById(id);
        if(flag){
            return AjaxResult.success("成功");
        }
        return AjaxResult.error(10001,"失败");
    }
}
